package ${package.Controller};

import org.springframework.web.bind.annotation.RequestMapping;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>
import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 */
@Slf4j
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
@Api(value = "管理接口",tags = "管理接口")
@RequestMapping("${entity?uncap_first}")
public class ${table.controllerName} {
</#if>

    @Autowired
    private ${table.serviceName}  ${table.serviceName?uncap_first};

    // 新增或者更新
    @PostMapping
    public boolean save(@RequestBody ${entity} ${table.entityPath}) {
        return ${table.serviceName?uncap_first}.saveOrUpdate(${table.entityPath});
    }

    @DeleteMapping("/{id}")
    public Boolean delete(@PathVariable Integer id) {
        return ${table.serviceName?uncap_first}.removeById(id);
    }

    @PostMapping("/del/batch")
    public boolean deleteBatch(@RequestBody List<Integer> ids) {
        return ${table.serviceName?uncap_first}.removeByIds(ids);
    }

    @GetMapping
    public List<${entity}> findAll() {
        return ${table.serviceName?uncap_first}.list();
    }

    @GetMapping("/{id}")
    public ${entity} findOne(@PathVariable Integer id) {
        return ${table.serviceName?uncap_first}.getById(id);
    }

    @GetMapping("/page")
    public Page<${entity}> findPage(@RequestParam Integer pageNum,
            @RequestParam Integer pageSize) {
            QueryWrapper<${entity}> queryWrapper = new QueryWrapper<>();
            queryWrapper.orderByAsc("id");

        return ${table.serviceName?uncap_first}.page(new Page<>(pageNum, pageSize), queryWrapper);
    }




}
</#if>
